
#include "admin.h"

void rp_rpointd_adm(int fd, short event, void *arg)
{
	static char fname[] = "rp_rpointd_adm";
	static char msg[] = "fatal error";
	static Err err;
	static OpCode code;
	FLOG_IN(fname);
	
	if (rp_comm_recv(fd, (void*)&code, sizeof(OpCode)) != E_OK)
	{
		rp_log(LOG_WARNING, fname, "Failed to receive the command");
	}

	switch (code)
	{
		case (OP_SHUTDOWN) : {
			int fd_hsk;
			int count;
			int ioport;
			struct timeval time;			
			err = rp_score_set_code(global.score, OP_SHUTDOWN);
			err = rp_comm_tcp_client_init(&fd_hsk, &config.addr_hsk);
			count = rp_comm_send(fd_hsk, &code, sizeof(OpCode));
			count = rp_comm_recv(fd_hsk, (void *)&ioport, sizeof(int));
			err = rp_comm_close(fd_hsk);
			time.tv_sec = 0;
			time.tv_usec = 0;
			event_loopexit(&time);
			break;
		}
		case (OP_SHUTDOWN_FORCE) : {
			break;
		}
		case (OP_PAUSE) : {
			break;
		}
		case (OP_RESUME) : {
			break;
		}
		default : {
			rp_log(LOG_WARNING, fname, "Invalid command");
			break;
		}
	}
	
	code = OP_NONE;
	FLOG_OUT(fname);
	return;
}

